define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'urge_stats/index' + location.search,
                    add_url: 'urge_stats/add',
                    edit_url: 'urge_stats/edit',
                    del_url: 'urge_stats/del',
                    multi_url: 'urge_stats/multi',
                    import_url: 'urge_stats/import',
                    table: 'urge_stats',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'date', title: __('Date'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'app.name', title: __('应用名'), operate:false},
                        {field: 'app_id', title: __('应用名'),addclass: 'selectpage', extend:'data-source="ajax/getApp" ',visible:false,defaultValue:'11'},
                        {field: 'game_id', title: __('模块游戏'),addclass: 'selectpage', extend:'data-source="game/index" ',visible:false},
                        {field: 'game.name', title: __('模块游戏'), operate:false},
                        {field: 'details', title: __('节点数据'),operate:false, formatter:function(value,row,index){
                                 if(value){
                                     return '<div style="white-space: pre-wrap;">'+value+'</div>';
                                 }
                            }},
                        {field: 'count', title: __('Count'), operate:false, sortable: true,},
                        {field: 'ratio', title: __('Ratio'), operate:false, sortable: true,},
                        //{field: 'ext', title: __('Ext'), operate:false},sort:true,


                        //{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});